package com.kgajowy.result;

import com.kgajowy.utils.IPrintable;

import edu.pjwstk.jps.result.IBagResult;
import edu.pjwstk.jps.result.ISingleResult;

import java.util.ArrayList;
import java.util.Collection;

public class BagResult extends CollectionResult implements IBagResult, IPrintable  {

    public BagResult() {
        this.col = new ArrayList<ISingleResult>();
    }
        
    public BagResult(ISingleResult... args) {
        this.col = new ArrayList<ISingleResult>();
        for (ISingleResult arg : args) {
            col.add(arg);
        }
    }
    
    public BagResult(ArrayList<SingleResult> list) {
        this.col = new ArrayList<ISingleResult>();
        col.addAll(list);
    }
    
    public void add(ISingleResult res) {
        this.col.add(res);
    }
    
    public void add(CollectionResult res) {
        this.col.addAll(res.getElements());
    }
    
    @Override
    public Collection<ISingleResult> getElements() {
        return col;
    }
    
    @Override
    public String stringme() {
        String result = "";
        int i = 0;
        result += "bag(";
        for ( ISingleResult item : col ){
            if ( i > 0 ) { result += ", "; } //separator
            result += ((SingleResult)item).stringme() ;
            ++i;
        }
        result += ")";
        
        return result;
        
    }

}
